package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/3/1.
 */
public class LC50 {

    public double myPow(double x, int n) {
        if (n == 0 || x == 1) {
            return 1;
        }

        if (x == -1) {
            return n % 2 == 0 ? 1 : -1;
        }

        if (n == Integer.MIN_VALUE) {
            return 0;
        }

        if (n > 0) {
            double half = myPow(x, n / 2);
            return half * half * (n % 2 == 0 ? 1 : x);
        } else {
            n = Math.abs(n);
            double half = myPow(x, n / 2);
            return 1.0 / (half * half * (n % 2 == 0 ? 1 : x));
        }
    }

    public static void main(String[] args) {
        LC50 an = new LC50();
        System.out.println(an.myPow(-1.0, -2147483648));
    }
}
